package ltd.dujiabao.capability.domain.capmng.cap;

import java.time.LocalDateTime;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.springframework.lang.Nullable;

import ltd.dujiabao.capability.common.domain.AuditableEntity;

/**
 * @author : DuJiabao
 * @Project : ddd-capability
 * @Time : 2024/4/6 21:23
 * @Desc :
 */
public class Capability extends AuditableEntity {
    private final CapabilityIdentity identity;

    private final Map<String, Object> modules = new HashMap<>();

    public Capability(LocalDateTime createdAt, Long createdBy, String devModelId, String hardwareVer, String firmwareVer) {
        super(createdAt, createdBy);
        identity = new CapabilityIdentity(devModelId, hardwareVer, firmwareVer);
    }

    public Capability addModule(String key, Object body) {
        modules.put(key, body);
        return this;
    }

    public Capability addModules(Map<String, Object> modules) {
        this.modules.putAll(modules);
        return this;
    }

    public Map<String, Object> getModules() {
        return Collections.unmodifiableMap(modules);
    }

    @Nullable
    public Object getModule(String key) {
        return modules.get(key);
    }

    public String getDevModelId() {
        return identity.getDevModelId();
    }

    public String getHardwareVer() {
        return identity.getHardwareVer();
    }

    public String getFirmwareVer() {
        return identity.getFirmwareVer();
    }

    public CapabilityIdentity getIdentity() {
        return identity;
    }

    public boolean isEmpty() {
        return modules.isEmpty();
    }
}
